package com.hencoder.hencoderpracticedraw1.practice;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

import com.hencoder.hencoderpracticedraw1.R;

public class Practice11PieChartView extends View {

    private Paint paint,paint1;
    private int w;
    private int h;

    public Practice11PieChartView(Context context) {
        super(context);
    }

    public Practice11PieChartView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Practice11PieChartView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        this.w=w;
        this.h=h;
    }
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        float centerW=w/2;
        float centerH=h/2;
        paint=new Paint();
        paint.setStyle(Paint.Style.STROKE);
        paint.setColor(getResources().getColor(R.color.white));
        paint1=new Paint();
        paint1.setColor(getResources().getColor(R.color.colorAccent));
        float r=150;
        RectF rectF_red=new RectF(centerW-170,centerH-170,centerW+130,centerH+130);
        canvas.drawArc(rectF_red,180,120,true,paint1);
        float y= (float) (Math.sin(Math.PI*60/180)*r);
//        (Math.PI*30/180)
        float x= (float) (Math.sin(Math.PI*30/180)*r);
        Path path=new Path();
        path.moveTo(centerW-20-x,centerH-20-y);
        path.lineTo(centerW-40-x,centerH-40-y);
        path.lineTo(centerW-150-x,centerH-40-y);
        paint.setTextSize(51);
        canvas.drawText("java",centerW-150-x,centerH-40-y,paint);
        canvas.drawPath(path,paint);
        paint1.setColor(getResources().getColor(R.color.colorPrimary));
        RectF rectF_blue=new RectF(centerW-150,centerH-150,centerW+150,centerH+150);
        canvas.drawArc(rectF_blue,60,120,true,paint1);
        paint1.setColor(getResources().getColor(R.color.yellow));
        RectF rectF_yellow=new RectF(centerW-150,centerH-150,centerW+150,centerH+150);
        canvas.drawArc(rectF_yellow,10,45,true,paint1);

//        综合练习
//        练习内容：使用各种 Canvas.drawXXX() 方法画饼图

    }
}
